KISSY.use("node",function(S,Node){ 
var arr = new Array();
arr.push("");
arr.push("label-success");
arr.push("label-warning");
arr.push("label-important");
arr.push("label-info");
arr.push("label-inverse");
arr.push("");
var DOM = KISSY.DOM;
var s = DOM.get('.signday-calendar');
TimeSet(s,-7,'max');
var s = DOM.get('.editday-calendar');
TimeSet(s,-7,'max');
	$(".bui-tab-item").on("click",function(){
		$(".bui-tab-item").removeClass("bui-tab-item-selected");
		$(this).addClass("bui-tab-item-selected");
		var toolid =$(this).attr('data-toolid');
		var toolname =$(this).attr('data-toolname');
		var str = '<span class="label '+arr[toolid]+'">'+toolname+'设置</span>';
		$(".title").empty();
		$(str).appendTo(".title");
		$('.toolid').val(toolid);
		$('.well').addClass("hide");
		getcfg(toolid);
		// loadmsgpage(1,ac);
	});
	function getcfg(toolid){
		KISSY.io({
				url: "/?a=tool_get_cfg_ajax&m=home&c=admin",
				data: {"toolid":toolid},
				type: "post",
				// function请求成功的回调,回调参数为 data(内容),textStatus(请求状态),xhr(ajax对象)
				success: function(data, textStatus) {
					var cfgform = $('.cfgform,.form');
					for(var i=0;i<cfgform.len();i++){
						var key = cfgform.item(i).attr("data-post");
						cfgform.item(i).val(data[key]);
						var node = cfgform.item(i).getDOMNode();
						if(node.type=="checkbox"){
							if(data[key]==1){
								node.checked=true;
							}else{
								node.checked=false;
							}
						}
					}
				},
				complete: function(data){
					$('.well').removeClass("hide");
				},
				error: function(){
					alert('error');
				},
				dataType:"jsonp"
			});
	}
	$('.cfgform').on("change",function(){
		$(".save_cfg").fire("click");
	});
	$('.form').on("change",function(){
		$(".save_base_cfg").fire("click");
	});
	$('.save_cfg').on("click",function(){
		var toolid = $('.toolid').val();
		var cfgform = $('.cfgform');
		var data = new Array();
		data["toolid"]=toolid;
		for(var i=0;i<cfgform.len();i++){
			var key = cfgform.item(i).attr("data-post");
			var node = cfgform.item(i).getDOMNode();
			if(node.type=="checkbox"){
				data[key]=node.checked;
			}else{
				data[key]=node.value;
			}
		}
		KISSY.io({
				url: "/?a=tool_cfg_ajax&m=home&c=admin",
				data: {"toolid":data["toolid"],
					   "follow_weitao":data["follow_weitao"],
					   "live_events":data['live_events'],
					   "live_buyers":data['live_buyers'],
					   "new_commers":data['new_commers'],
					   "send_gifts":data['send_gifts'],
					   "upload_items":data['upload_items'],
					   "upload_shares":data['upload_shares'],
					   "upload_pics":data['upload_pics']},
				type: "post",
				success: function(data, textStatus) {
					if(data.status==0){alert("保存失败");}
				},
				complete: function(data){
					
				},
				error: function(){
					alert('error');
				},
				//发送请求类型是jsonp
				dataType:"jsonp"
			});
	});
	$('.save_base_cfg').on("click",function(){
		var toolid = $('.toolid').val();
		var cfgform = $('.form');
		var data = new Array();
		data["toolid"]=toolid;
		for(var i=0;i<cfgform.len();i++){
			var key = cfgform.item(i).attr("data-post");
			var node = cfgform.item(i).getDOMNode();
			if(node.type=="checkbox"){
				data[key]=node.checked;
			}else{
				data[key]=node.value;
			}
		}
		KISSY.io({
				url: "/?a=tool_cfg_ajax&m=home&c=admin",
				data: {"toolid":data["toolid"],
					  "save":"base",
					  "shop_banner":data["shop_banner"],
					  "shop_banner_url":data["shop_banner_url"],
					  "shop_sign_day":data["shop_sign_day"],
					  "shop_eidt_day":data["shop_eidt_day"],
					  "shop_srt":data["shop_srt"],
					  "indu_art":data["indu_art"],
					  "shop_srtp":data["shop_srtp"],
					  "indu_arr":data["indu_arr"],
					  "shop_ccp":data["shop_ccp"],
					  "indu_acr":data["indu_acr"],
					  "shop_punc":data["shop_punc"],
					  "indu_apts":data["indu_apts"],
					  "shop_gerd":data["shop_gerd"],
					  "indu_iasgr":data["indu_iasgr"],
					  "shop_sellerCredit":data["shop_sellerCredit"],
					  "shop_auctionCount":data["shop_auctionCount"],
					  "shop_delivery_score":data["shop_delivery_score"],
					  "shop_service_score":data["shop_service_score"],
					  "shop_item_score":data["shop_item_score"],
					  "shop_delivery_red":data["shop_delivery_red"],
					  "shop_service_red":data["shop_service_red"],
					  "shop_item_red":data["shop_item_red"],
					  "shop_tmall":data["shop_tmall"]},
				type: "post",
				success: function(data, textStatus) {
					if(data.status==0){alert("保存失败");}
				},
				complete: function(data){
				},
				error: function(){
					alert('error');
				},
				dataType:"jsonp"
			});
	});
});